package com.yy.bolg.service.impl;

import com.yy.bolg.dao.EvaluateDao;
import com.yy.bolg.dao.FeedbackDao;
import com.yy.bolg.dao.WorkOrderDao;
import com.yy.bolg.entity.AccessoryBean;
import com.yy.bolg.entity.ElectricianBean;
import com.yy.bolg.entity.EvaluateBean;
import com.yy.bolg.exception.LackParameterException;
import com.yy.bolg.exception.OtherThingsException;
import com.yy.bolg.service.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 评价Service实现类，对接口里的方法进行构造填充
 * @author enmaoFu
 * @date 2024-12-13
 */
@Service("EvaluateService")
public class EvaluateServiceImpl implements EvaluateService {

    @Autowired
    private EvaluateDao evaluateDao;

    @Override
    public void add(EvaluateBean bean) throws Exception {
        if(StringUtils.isEmpty(bean.getPsFeedbackCode())){
            throw new LackParameterException("上报编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsWorkOrderCode())){
            throw new LackParameterException("工单编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsElectricianCode())){
            throw new LackParameterException("电工编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsElectricianName())){
            throw new LackParameterException("电工姓名不能为空");
        }

        try {
            evaluateDao.add(bean);
        } catch (Exception e) {
            e.printStackTrace();
            throw new OtherThingsException("添加数据失败");
        }
    }

    @Override
    public void update(EvaluateBean bean) throws Exception {
        if(StringUtils.isEmpty(bean.getPsFeedbackCode())){
            throw new LackParameterException("上报编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsWorkOrderCode())){
            throw new LackParameterException("工单编号不能为空");
        }

        try {
            evaluateDao.update(bean);
        } catch (Exception e) {
            e.printStackTrace();
            throw new OtherThingsException("添加数据失败");
        }
    }

    @Override
    public List<EvaluateBean> findAllByWorkOrderCode(EvaluateBean bean) throws Exception {
        if(StringUtils.isEmpty(bean.getPsWorkOrderCode())){
            throw new LackParameterException("工单编号不能为空");
        }
        try {
            return evaluateDao.findAllByWorkOrderCode(bean);
        } catch (Exception e) {
            e.printStackTrace();
            throw new LackParameterException(e.getMessage());
        }
    }

    @Override
    public EvaluateBean findOneByCode(EvaluateBean bean) throws Exception {
        if (StringUtils.isEmpty(bean.getPsWorkOrderCode())) {
            throw new LackParameterException("工单编号不能为空");
        }

        try {
            return evaluateDao.findOneByCode(bean.getPsWorkOrderCode());
        } catch (Exception e) {
            e.printStackTrace();
            throw new OtherThingsException("暂无数据");
        }
    }

    @Override
    public List<EvaluateBean> findAllByElectricianCode(EvaluateBean bean) throws Exception {
        if (StringUtils.isEmpty(bean.getPsElectricianCode())) {
            throw new LackParameterException("电工编号不能为空");
        }

        try {
            return evaluateDao.findAllByElectricianCode(bean);
        } catch (Exception e) {
            e.printStackTrace();
            throw new OtherThingsException("暂无数据");
        }
    }

    @Override
    public List<EvaluateBean> findAllByEvaluateCustomerCode(EvaluateBean bean) throws Exception {
        if (StringUtils.isEmpty(bean.getPsEvaluateCustomerCode())) {
            throw new LackParameterException("业主编号不能为空");
        }

        try {
            return evaluateDao.findAllByEvaluateCustomerCode(bean);
        } catch (Exception e) {
            e.printStackTrace();
            throw new OtherThingsException("暂无数据");
        }
    }
}
